package com.navinfo.tripanalysis.common.arithmetic;

import com.navinfo.tripanalysis.common.arithmetic.common.CommonData;
import com.navinfo.tripanalysis.common.arithmetic.common.OuterStatisticData;
import com.navinfo.tripanalysis.common.arithmetic.common.VarCommon;
import com.navinfo.tripanalysis.common.arithmetic.common.VehicleInfo;
import com.navinfo.tripanalysis.common.arithmetic.custom.VarRangeGasOpenPercent;
import com.navinfo.tripanalysis.common.arithmetic.custom.VarUreaInjection;
import com.navinfo.tripanalysis.common.arithmetic.custom.VarVehicleLoadType;
import com.navinfo.tripanalysis.common.arithmetic.enums.LoadTypeEnum;
import com.navinfo.tripanalysis.common.arithmetic.enums.RangeGasOpenPercentEnum;
import com.navinfo.tripanalysis.common.arithmetic.manager.AbstractArithmetic;
import com.navinfo.tripanalysis.common.util.ArithmeticUtils;
import com.navinfo.tripanalysis.common.util.BigDecimalUtils;

import java.math.BigDecimal;
import java.util.Optional;

/**
 * 东风新增尿素算法<br/>
 * 依赖{@link }的D004秒速喷射量<br/>
 * 输出：统计(尿素喷射量)<br/>
 * @author web
 */
public class UreaInjection_DF extends AbstractArithmetic<VarUreaInjection> {


    @Override
    public void calculate() {
        logger.debug("===============东风尿素算法开始===========");
        CommonData commonData = getCommonData();
        double ureaInjectionNew = Optional.ofNullable(commonData.getUreaInjection()).orElse(0.00);

        //无效值不参与计算
        if (ureaInjectionNew == 0 ){
            return;
        }

        int ureaOutput = ArithmeticUtils.massToVolume(ureaInjectionNew, commonData.getAtmosphericTem());


        VarUreaInjection var = getObj();
        logger.debug("进入尿素喷射量算法.");

            //累加尿素喷射量的公共统计变量
            if(null != var){
                var.setUreaInjection(
                        Optional.ofNullable(var.getUreaInjection()).orElse(0) + ureaOutput);
            }

        logger.debug("===============东风尿素喷射量结束===========");
    }

    @Override
    public void collect(OuterStatisticData statisticDataOut) {
        VarUreaInjection var = getObj();

        statisticDataOut.setTripUrea(var.getUreaInjection());
    }

}
